package ru.spb.osll.myfit.client.dialog;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Created by IntelliJ IDEA.
 * User: Victor
 * Date: 11.05.11
 * Time: 22:50
 * To change this template use File | Settings | File Templates.
 */
public class ConfirmationDialog extends DialogBox {

    private ConfirmationDialogListener m_listener;

    public ConfirmationDialog(String text, String label){
        setText(text);

        Label m_queryLabel =  new Label(label);

        Button m_buttonYes = new Button();
        m_buttonYes.setWidth("50px");
        m_buttonYes.setText("Yes");
        m_buttonYes.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                hide();
                if(m_listener != null)
                    m_listener.confirmed();
            }
        });


        Button m_buttonNo = new Button();
        m_buttonNo.setWidth("50px");
        m_buttonNo.setText("No");
        m_buttonNo.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                hide();
            }
        });

        HorizontalPanel hPanelButton = new HorizontalPanel();
        hPanelButton.setWidth("100%");
        hPanelButton.add(m_buttonYes);
        hPanelButton.add(m_buttonNo);
        hPanelButton.setCellWidth(m_buttonYes, "50%");
        hPanelButton.setCellHorizontalAlignment(m_buttonYes, HasHorizontalAlignment.ALIGN_CENTER);
        hPanelButton.setCellWidth(m_buttonNo, "50%");
        hPanelButton.setCellHorizontalAlignment(m_buttonNo, HasHorizontalAlignment.ALIGN_CENTER);
        
        VerticalPanel vPanel = new VerticalPanel();
        vPanel.add(m_queryLabel);
        vPanel.add(hPanelButton);
        vPanel.setCellHeight(m_queryLabel, "50px");
        vPanel.setCellHorizontalAlignment(m_queryLabel, HasHorizontalAlignment.ALIGN_CENTER);
        vPanel.setCellVerticalAlignment(m_queryLabel, HasVerticalAlignment.ALIGN_MIDDLE);
        vPanel.addStyleName("dialogVPanel");
        this.setWidget(vPanel);

    }

    public void setListener(ConfirmationDialogListener listener){
        m_listener = listener;
    }

}
